﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace tms.Migrations
{
    public partial class menu7 : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "TmsMenu",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MenuName = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: false),
                    MenuCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ParentId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MenuRoute = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    MenuType = table.Column<int>(type: "int", nullable: false),
                    ComponentPath = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    Permission = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true),
                    ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
                    CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                    LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
                    DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
                    DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TmsMenu", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "TmsMenu_Role",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    MenuId = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
                    RoleId = table.Column<Guid>(type: "uniqueidentifier", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TmsMenu_Role", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TmsMenu_Role_TmsMenu_MenuId",
                        column: x => x.MenuId,
                        principalTable: "TmsMenu",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_TmsMenu_Role_TmsRole_RoleId",
                        column: x => x.RoleId,
                        principalTable: "TmsRole",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TmsFlow_MenuId",
                table: "TmsFlow",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_TmsMenu_Role_MenuId",
                table: "TmsMenu_Role",
                column: "MenuId");

            migrationBuilder.CreateIndex(
                name: "IX_TmsMenu_Role_RoleId",
                table: "TmsMenu_Role",
                column: "RoleId");

            migrationBuilder.AddForeignKey(
                name: "FK_TmsFlow_TmsMenu_MenuId",
                table: "TmsFlow",
                column: "MenuId",
                principalTable: "TmsMenu",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_TmsFlow_TmsMenu_MenuId",
                table: "TmsFlow");

            migrationBuilder.DropTable(
                name: "TmsMenu_Role");

            migrationBuilder.DropTable(
                name: "TmsMenu");

            migrationBuilder.DropIndex(
                name: "IX_TmsFlow_MenuId",
                table: "TmsFlow");
        }
    }
}
